package com.impress.model;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import android.text.TextUtils;



/**
 * Item实体类，实现一系列与item有关的操作
 * @author pluto
 * @version 1.0.1
 * @version 1.0.2 add an additional attribute categories
 * @version 1.0.3 add summary field, and downloadState field.
 */
public class Item implements Serializable {


	public Item() {
		super();
		categories = new ArrayList<String>();
	}
	//member fields of item ref to item column description in provider: FeedData
	private int _id;
	private String atomID;
	private String alternateUrl;
	private String content;
	private String title;
	private String feedTitle;
	private String feedID;
	private String summary;
	private int readState;
	private int readStatePending;
	private int shareState;
	private int shareStatePending;
	private int starredState;
	private int starredStatePending;
	private int likeState;
	private int likeStatePending;
	private int downloadState;
	private long updateTimestamp;
	private long insertTimestamp;
	private String author;
	private String previewImg;
	
	/**
	 * additional attribute categories, contain label names associated with the item
	 */
	public List<String> categories;
	
	/**
	 * @return the categories
	 */
//	public List<String> getCategories() {
//		return categories;
//	}
	/**
	 * @param categories the categories to set
	 */
//	public void setCategories(List<String> categories) {
//		this.categories = categories;
//	}
	/**
	 * @return the _id
	 */
	public int get_id() {
		return _id;
	}
	/**
	 * @param _id the _id to set
	 */
	public void set_id(int _id) {
		this._id = _id;
	}
	/**
	 * @return the atomID
	 */
	public String getAtomID() {
		return atomID;
	}
	/**
	 * @param atomID the atomID to set
	 */
	public void setAtomID(String atomID) {
		this.atomID = atomID;
	}
	/**
	 * @return the alternateUrl
	 */
	public String getAlternateUrl() {
		return alternateUrl;
	}
	/**
	 * @param alternateUrl the alternateUrl to set
	 */
	public void setAlternateUrl(String alternateUrl) {
		this.alternateUrl = alternateUrl;
	}
	/**
	 * @return the content
	 */
	public String getContent() {
		return content;
	}
	/**
	 * @param content the content to set
	 */
	public void setContent(String content) {
		this.content = content;
	}
	/**
	 * @return the title
	 */
	public String getTitle() {
		return title;
	}
	/**
	 * @param title the title to set
	 */
	public void setTitle(String title) {
		this.title = title;
	}
	/**
	 * @return the feedTitle
	 */
	public String getFeedTitle() {
		return feedTitle;
	}
	/**
	 * @param feedTitle the feedTitle to set
	 */
	public void setFeedTitle(String feedTitle) {
		this.feedTitle = feedTitle;
	}
	/**
	 * @return the feedID
	 */
	public String getFeedID() {
		return feedID;
	}
	/**
	 * @param feedID the feedID to set
	 */
	public void setFeedID(String feedID) {
		this.feedID = feedID;
	}
	/**
	 * @return the readState 1 for read;  0 for unread
	 */
	public int getReadState() {
		return readState;
	}
	/**
	 * @param readState the readState to set
	 */
	public void setReadState(int readState) {
		this.readState = readState;
	}
	/**
	 * @return the shareState
	 */
	public int getShareState() {
		return shareState;
	}
	/**
	 * @param shareState the shareState to set
	 */
	public void setShareState(int shareState) {
		this.shareState = shareState;
	}
	/**
	 * @return the starredState
	 */
	public int getStarredState() {
		return starredState;
	}
	/**
	 * @param starredState the starredState to set
	 */
	public void setStarredState(int starredState) {
		this.starredState = starredState;
	}
	/**
	 * @return the likeState
	 */
	public int getLikeState() {
		return likeState;
	}
	/**
	 * @param likeState the likeState to set
	 */
	public void setLikeState(int likeState) {
		this.likeState = likeState;
	}
	/**
	 * @return the readStatePending
	 */
	public int getReadStatePending() {
		return readStatePending;
	}
	/**
	 * @param readStatePending the readStatePending to set
	 */
	public void setReadStatePending(int readStatePending) {
		this.readStatePending = readStatePending;
	}
	/**
	 * @return the shareStatePending
	 */
	public int getShareStatePending() {
		return shareStatePending;
	}
	/**
	 * @param shareStatePending the shareStatePending to set
	 */
	public void setShareStatePending(int shareStatePending) {
		this.shareStatePending = shareStatePending;
	}
	/**
	 * @return the starredStatePending
	 */
	public int getStarredStatePending() {
		return starredStatePending;
	}
	/**
	 * @param starredStatePending the starredStatePending to set
	 */
	public void setStarredStatePending(int starredStatePending) {
		this.starredStatePending = starredStatePending;
	}
	/**
	 * @return the likeStatePending
	 */
	public int getLikeStatePending() {
		return likeStatePending;
	}
	/**
	 * @param likeStatePending the likeStatePending to set
	 */
	public void setLikeStatePending(int likeStatePending) {
		this.likeStatePending = likeStatePending;
	}
	/**
	 * @return the updateTimestamp
	 */
	public long getUpdateTimestamp() {
		return updateTimestamp;
	}
	/**
	 * @param updateTimestamp the updateTimestamp to set
	 */
	public void setUpdateTimestamp(long updateTimestamp) {
		this.updateTimestamp = updateTimestamp;
	}
	/**
	 * @return the insertTimestamp
	 */
	public long getInsertTimestamp() {
		return insertTimestamp;
	}
	/**
	 * @param insertTimestamp the insertTimestamp to set
	 */
	public void setInsertTimestamp(long insertTimestamp) {
		this.insertTimestamp = insertTimestamp;
	}
	/**
	 * @return the author
	 */
	public String getAuthor() {
		return author;
	}
	/**
	 * @param author the author to set
	 */
	public void setAuthor(String author) {
		this.author = author;
	}
	
	/**
	 * 根据给定的状态，设定相应的状态值
	 * @param state kept-unread,read,starred,broadcast,like.
	 */
	public void setState(String state){
		if(TextUtils.equals(state, "kept-unread")){
			readState = 0;
		}else if(TextUtils.equals(state, "read")){
			readState = 1;
		}else if(TextUtils.equals(state, "starred")){
			starredState = 1;
		}else if(TextUtils.equals(state, "broadcast")){
			shareState = 1;
		}else if(TextUtils.equals(state, "like")){
			likeState = 1;
		}
	}
	
	public void setSummary(String summary) {
		this.summary = summary;
	}
	public String getSummary() {
		return summary;
	}
	public void setDownloadState(int downloadState) {
		this.downloadState = downloadState;
	}
	public int getDownloadState() {
		return downloadState;
	}
	/**
	 * initial the state_pending be the same as state.
	 */
	public void initStatePending(){
		readStatePending = readState;
		starredStatePending = starredState;
		shareStatePending = shareState;
		likeStatePending = likeState;
	}
	
	/**
	 * toggle the state value: 1 to 0, 0 to 1.
	 * @param state the state name
	 */
	public void toggleState(String state){
		if(state == "read"){
			if (readState == 1) {
				readState = 0;
			}else {
				readState = 1;
			}
		}else if (state == "like") {
			if (likeState == 1) {
				likeState = 0;
			}else {
				likeState = 1;
			}
		}else if (state == "star") {
			if (starredState == 1) {
				starredState = 0;
			}else {
				starredState = 1;
			}
		}else if (state == "share") {
			if (shareState == 1) {
				shareState = 0;
			}else {
				shareState = 1;
			}
		}
	}
	
	/**
	 * check if all the state and pending state pairs are the same.
	 * @return
	 */
	public boolean checkStateEqual(){
		return (readState == readStatePending) && (likeState == likeStatePending)
		&& (shareState == shareStatePending) && (starredState == starredStatePending);
	}
	
	public boolean isRead(){
		return readStatePending==1;
	}
	
	public boolean isLike(){
		return likeStatePending==1;
	}
	
	public boolean isShare(){
		return shareStatePending==1;
	}
	
	public boolean isStarred(){
		return starredStatePending==1;
	}
	public String getPreviewImg() {
		return previewImg;
	}
	public void setPreviewImg(String previewImg) {
		this.previewImg = previewImg;
	}
	
	
}
